#include <cstdio>
#include <algorithm>
using namespace std;

int S[205];

int getf(int x) {
	if (S[x] == x) {
		return x;
	}
	return S[x] = getf(S[x]);
}

void merge(int x, int y) {
	if (getf(x) != getf(y)) {
		S[S[x]] = S[y];
		S[x] = S[y];
	}
}

int main() {
	int n, x;
	scanf("%d", &n);
	for (int i = 0; i <= n; ++i) {
		S[i] = i;
	}
	for (int i = 1; i <= n; ++i) {
		while (1) {
			scanf("%d", &x);
			if (x == 0) break;
			merge(i, x);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (S[i] == i) ++ans;
	}
	printf("%d\n", ans);
	return 0;
}